package com.liu.wode.config;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class LoginHandlerInterceptor implements HandlerInterceptor{
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        //拦截器
        Object loginUser= request.getSession().getAttribute("loginUser");
        if(loginUser==null){
            request.setAttribute("msg","请先登录");//拦截提示
            request.getRequestDispatcher("/index").forward(request,response);//拦截返回页面
            return false;
        }else{
            return true;
        }
    }


}
